package com.wh.springkafka.producer;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

public class SamplePartition implements Partitioner {

    /**
     * 什么样的数据，进入什么样的partition
     * @param topid
     * @param key
     * @param keybates
     * @param value
     * @param valueBytes
     * @param cluster
     * @return
     */
    @Override
    public int partition(String topid, Object key, byte[] keybates, Object value,
                         byte[] valueBytes, Cluster cluster) {
        // key-1,key-2,key-3,key-4
        String keyStr = key+"";
        String keyInt = keyStr.substring(4);
        System.out.println(" SamplePartition keyStr: "+keyStr + "keyInt: "+keyInt);
        return Integer.parseInt(keyInt)%2;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> map) {

    }
}
